<template>
	<view >
		<tui-tabbar :current="current"  backdropFilter :backgroundColor="backgroundColor" :tabBar="tabBar" :color="color" :selectedColor="selectedColor" @click="tabbarSwitch"></tui-tabbar>
	</view>
</template>

<script>
 
export default {
	props:{
		current: {
			type: Number,
			default: 0
		},
		backgroundColor:{
			type: Number | String,
			default: '#f8f8f8'
		},
		color:{
			type: Number | String,
			default: '#777'
		},
		selectedColor:{
			type: Number | String,
			default: '#AC9157'
		},
		tabBar: {
			type: Array,
			default () {
				return [
					{
						pagePath: '/pages/tabbar/index',
						text: '首页',
						iconPath: '/static/logo.png',
						selectedIconPath: '/static/logo.png'
					},
					{
						pagePath: '/pages/tabbar/goodsType',
						text: '分类',
						iconPath: '/static/logo.png',
						hump: true,
						selectedIconPath: '/static/logo.png'
					},
					{
						pagePath: '/pages/tabbar/shoppingCar',
						text: '购物车',
						iconPath: '/static/logo.png',
						hump: true,
						selectedIconPath: '/static/logo.png'
					},
					{
						pagePath: '/pages/tabbar/my',
						text: '我的',
						iconPath: '/static/logo.png',
						selectedIconPath: '/static/logo.png',
						num: 2,
						isDot: true,
						verify: true
					}
				];
			}
		},
	},
	onLoad() {
		// this.getLogin();
	},
	  methods: {
		getLogin(){
			wx.login({
				success: (e) => {
					this.tui.request("/basic-capi/wxlogin", "post", {code:e.code}).then((res) => {
						uni.setStorageSync('userInfo',res.data.userInfo)
					}).catch((res) => {
						console.log(res)
					})
					
				}
			})
		},
		tabbarSwitch(e) {
			if(!uni.getStorageSync('userInfo')){
				// #ifdef MP-WEIXIN
					this.getLogin();
				// #endif 
				
				// #ifdef H5 || APP-PLUS || MP-ALIPAY
				 
					uni.reLaunch({
						url:'/pages/login/index'
					})
					 
				// #endif 
			}
			
			if(e.index == this.$store.state.current){
				return
			}
			
			this.$store.state.current = e.index
			uni.reLaunch({
				url:e.pagePath
			})
		}
	}
}
</script>

<style>
	 
</style>
